package com.sdp.right.excel.importExcel;

import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.util.IOUtils;


public class ResettableInputStream extends InputStream {
	
	private final byte[] data;  // 内存缓存数据
	
    private int position = 0;
    
    public ResettableInputStream(InputStream sourceStream) throws IOException {
        this.data = IOUtils.toByteArray(sourceStream); // 将流数据读入内存
    }
    
	@Override
	public int read() throws IOException {
		if (position >= data.length) {
            return -1;
        }
        return data[position++] & 0xFF; // 返回无符号字节
	}

	public void reset() {
        position = 0; // 重置读取位置
    }
}
